<?php
/*
 * 配置加载类
 */
namespace core\lib;

class conf {

    static public $conf = array();

    static public function get($name, $file) {
        //判断缓存
        if (isset(self::$conf[$file])) {
            return self::$conf[$file][$name];
        } else {
            $path = XUE . '/core/config/' . $file . '.php';
            //判断配置文件是否存在
            if (is_file($path)) {
                $conf = include $path;
                //判断配置是否存在
                if (isset($conf[$name])) {
                    self::$conf[$file] = $conf; //用来判断缓存赋值
                    return $conf[$name];
                } else {
                    throw new \Exception('没有这个配置项' . $name);
                }
            } else {
                throw new \Exception('找不到配置文件' . $file);
            }
        }
    }
    
    static public function all($file){
        //判断缓存
        if (isset(self::$conf[$file])) {
            return self::$conf[$file];
        } else {
            $path = XUE . '/core/config/' . $file . '.php';
            //判断配置文件是否存在
            if (is_file($path)) {
                $conf = include $path;
                self::$conf[$file]=$conf;
                return $conf;
            } else {
                throw new \Exception('找不到配置文件' . $file);
            }
        }
    }

}
